/**
 * Copyright (c) Css Team
 * All rights reserved.
 *
 * This file DictMan.java creation date: [Jan 13, 2014 15:21:03 PM] by liuzhb
 * http://www.css.com.cn
 */
package com.css.apps.base.dict.action;

import com.css.apps.base.dict.model.SDict;
import com.css.apps.base.dict.service.DictMan;
import com.css.apps.base.dict.service.QueryDict;
import com.css.db.query.QueryCache;
import com.css.util.Messages;
import com.css.util.StringHelper;
import com.css.webbase.webwork.action.UserAction;
import com.opensymphony.xwork.Action;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.ArrayList;
import java.util.List;

@SuppressWarnings("serial")
public class DirDictFilter extends UserAction {

	private static Log log = LogFactory.getLog(DirDictFilter.class);
	private String tableName;
	private String param="";
	private List<SDict> dictList = new ArrayList<>();

	public String userGo() {
		try {
			if (StringHelper.isEmpty(tableName))
				return null;
			if(StringHelper.isNotEmpty(param)){
				String parentId = DictMan.getUuid("d_root", tableName);
				QueryCache qc = new QueryDict(" from SDict a where a.parentId = :parentId and a.name like:param order by code")
						.setParameter("parentId", parentId).setParameter("param","%"+param+"%");
				boolean isNoCache = qc.isNoCache();
				dictList = qc.listCache(-1);
			}else{
				dictList = DictMan.getDictType(tableName);
			}
			return Action.SUCCESS;
		} catch (Exception ex) {
			log.error(ex.getMessage(), ex);
			setMessage(Messages.getString("systemMsg.exception"));
			return Action.ERROR;
		}
	}

	public List<SDict> getDictList() {
		return dictList;
	}

	public void setDictList(List<SDict> dictList) {
		this.dictList = dictList;
	}

	public String getTableName() {
		return tableName;
	}

	public void setTableName(String tableName) {
		this.tableName = tableName;
	}

	public String getParam() {
		return param;
	}

	public void setParam(String param) {
		this.param = param;
	}
}
